import 'package:flutter/material.dart';
import 'package:x3_charts_core/chart_tools/chart_tools.dart';

///**
///* Description: 通用图表的点击信息provider
///               收集图表的各个模块的点位，直方图收集区域，折线图收集点位，还要收集每个X轴的区域（w:每个直方的宽度,h：直方最大宽度）
///*/
class GenericStackedChartTouchInfo extends ChangeNotifier {
  ///每个X轴的区域 - 不区分直方
  List<Rect> xRectList = [];

  ///第一个直方的区域列表
  List<Rect> firstRectList = [];

  ///第二个直方的区域列表
  List<Rect> secondRectList = [];

  ///第三个直方的区域列表
  List<Rect> thirdRectList = [];

  ///第一个折线图的点位
  List<Offset> firstPolyLineOffsetList = [];

  ///第二个折线图的点位
  List<Offset> secondPolyLineOffsetList = [];

  ///点击直方
  int clickOnTheHistogram(Offset anchorPoint) {
    if (xRectList.length == 0) {
      return -1;
    }
    int _index = xRectList.indexWhere((element) => ChartTools.contains(element, anchorPoint));
    return _index;
  }

  ///点击第一个直方
  int clickOnTheFirstHistogram(Offset anchorPoint) {
    if (firstRectList.length == 0) {
      return -1;
    }
    int _index = firstRectList.indexWhere((element) => ChartTools.contains(element, anchorPoint));

    return _index;
  }

  ///点击第二个直方
  int clickOnTheSecondHistogram(Offset anchorPoint) {
    if (secondRectList.length == 0) {
      return -1;
    }
    int _index = secondRectList.indexWhere((element) => ChartTools.contains(element, anchorPoint));

    return _index;
  }

  ///点击第三个直方
  int clickOnTheThirdHistogram(Offset anchorPoint) {
    if (thirdRectList.length == 0) {
      return -1;
    }
    int _index = thirdRectList.indexWhere((element) => ChartTools.contains(element, anchorPoint));

    return _index;
  }

  ///点击第一根折线 anchorPoint
  int clickOnTheFirstPolyline(Offset anchorPoint) {
    if (firstPolyLineOffsetList.length == 0) {
      return -1;
    }
    int _index = firstPolyLineOffsetList.indexWhere(
      (element) => ChartTools.contains(Rect.fromCenter(center: element, width: 5, height: 5), anchorPoint),
    );

    return _index;
  }

  ///点击第二根折线 anchorPoint
  int clickOnTheSecondPolyline(Offset anchorPoint) {
    if (secondPolyLineOffsetList.length == 0) {
      return -1;
    }
    int _index = secondPolyLineOffsetList.indexWhere(
      (element) => ChartTools.contains(Rect.fromCenter(center: element, width: 5, height: 5), anchorPoint),
    );

    return _index;
  }


}
